package com.example.busshop.service;

import com.example.busshop.common.service.LogicService;
import com.example.busshop.dao.CustomerDao;
import com.example.busshop.dao.OrderDao;
import com.example.busshop.entity.*;
import org.hibernate.resource.jdbc.internal.LogicalConnectionManagedImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
@Service
public class OrderService extends LogicService<OrderDao, Order,Long> {
    public OrderService(@Autowired OrderDao lr) {
        super(lr);
    }
    @Resource
    CustomerDao customerDao;
//    public Object chooseItems(Item item, double quantity,Long oid){
//        Map<String,Object> map= new HashMap<>();
//        Customer customer=customerDao.getReferenceById(cid);
//        double total=0.0;
//        Order order=getDAO().getReferenceById(oid);
//        Set<LineItem> lineItems= order.addItem(item,quantity);
//        for(LineItem lineItem:lineItems){
//            total=total+lineItem.getPrice()*lineItem.getQuantity();
//        }
//        getDAO().save(order);
//        map.put("total", total);
//        map.put("lineItems",lineItems);
//        return map;
//    }
    public int pay(Long oid){
        return getDAO().pay(oid);
    }
    public Set<LineItem> getLineItems(Long oid){
        Order order=getDAO().getReferenceById(oid);
        return order.getLineItems();
    }
}
